<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" >
</head>
<body>
<table class="table">
    <tr>
        <th>文件名</th>
        <th>创建时间</th>
        <th>大小</th>
        <th>操作</th>
    </tr>
    <tr th:each="file:${fileList}">
        <td th:text="${file.name}"></td>
        <td th:text="${file.time}"></td>
        <td th:text="${file.size}"></td>
        <td ><a href="#"  th:attr="data-url=${'/file/delByName?name='+ file.name}">删除</a><span>&nbsp</span><a th:href="${'/download/file?fileName='+ file.name}">下载</a></td>
    </tr>
</table>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/js/bootstrap.min.js"></script>
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" rel="stylesheet">
<script>

    $(".table tr td a").on("click",function (){

       var url =  $(this).attr("data-url");
       console.log(url);
       get(url,"","get");



    })
    function get(url,data,type){
        $.ajax({
            url:url,
            type:type,
            dataType:"json",
            success:function (res){
                if(res==true){
                    alert("删除成功");
                    window.location.reload()
                }else{
                    alert("删除失败，文件可能已经不存在");
                    window.location.reload()
                }
            }


        })
    }
</script>
</body>
</html>